<?php

/**
 * This is the model class for table "party_address".
 *
 * The followings are the available columns in table 'party_address':
 * @property integer $id
 * @property string $create_date
 * @property string $write_date
 * @property integer $create_uid
 * @property integer $write_uid
 * @property string $city
 * @property string $name
 * @property string $zip
 * @property integer $country
 * @property integer $sequence
 * @property integer $subdivision
 * @property string $streetbis
 * @property string $street
 * @property boolean $active
 * @property integer $party
 * @property string $relationship
 * @property integer $relative_id
 * @property boolean $is_work
 * @property boolean $is_school
 *
 * The followings are the available model relations:
 * @property ResUser $createU
 * @property PartyParty $party0
 * @property PartyParty $relative
 * @property ResUser $writeU
 * @property GnuhealthPatient[] $gnuhealthPatients
 */
class PartyAddress extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'party_address';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('party', 'required'),
			array('create_uid, write_uid, country, sequence, subdivision, party, relative_id', 'numerical', 'integerOnly'=>true),
			array('create_date, write_date', 'length', 'max'=>6),
			array('city, name, zip, streetbis, street, active, relationship, is_work, is_school', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, create_date, write_date, create_uid, write_uid, city, name, zip, country, sequence, subdivision, streetbis, street, active, party, relationship, relative_id, is_work, is_school', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'createU' => array(self::BELONGS_TO, 'ResUser', 'create_uid'),
			'party0' => array(self::BELONGS_TO, 'PartyParty', 'party'),
			'relative' => array(self::BELONGS_TO, 'PartyParty', 'relative_id'),
			'writeU' => array(self::BELONGS_TO, 'ResUser', 'write_uid'),
			'gnuhealthPatients' => array(self::HAS_MANY, 'GnuhealthPatient', 'current_address'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'create_date' => 'Create Date',
			'write_date' => 'Write Date',
			'create_uid' => 'Create Uid',
			'write_uid' => 'Write Uid',
			'city' => 'City',
			'name' => 'Name',
			'zip' => 'Zip',
			'country' => 'Country',
			'sequence' => 'Sequence',
			'subdivision' => 'Subdivision',
			'streetbis' => 'Streetbis',
			'street' => 'Street',
			'active' => 'Active',
			'party' => 'Party',
			'relationship' => 'Relationship',
			'relative_id' => 'Relative',
			'is_work' => 'Is Work',
			'is_school' => 'Is School',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('create_date',$this->create_date,true);
		$criteria->compare('write_date',$this->write_date,true);
		$criteria->compare('create_uid',$this->create_uid);
		$criteria->compare('write_uid',$this->write_uid);
		$criteria->compare('city',$this->city,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('zip',$this->zip,true);
		$criteria->compare('country',$this->country);
		$criteria->compare('sequence',$this->sequence);
		$criteria->compare('subdivision',$this->subdivision);
		$criteria->compare('streetbis',$this->streetbis,true);
		$criteria->compare('street',$this->street,true);
		$criteria->compare('active',$this->active);
		$criteria->compare('party',$this->party);
		$criteria->compare('relationship',$this->relationship,true);
		$criteria->compare('relative_id',$this->relative_id);
		$criteria->compare('is_work',$this->is_work);
		$criteria->compare('is_school',$this->is_school);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return PartyAddress the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
